package com.wecon.springdemo.test.serilalizTest;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @author Weikang  Wang
 * @program: com.wecon.springdemo.test.serilalizTest
 * @description:
 * @date 2020/7/8 15:32
 */
public class HelloKryo {

    public static void main(String[] args) throws Exception {
        Kryo kryo = new Kryo();
        kryo.register(MyKryoClass.class);

        MyKryoClass myKryoClass = new MyKryoClass();
        myKryoClass.value = "Hello Kryo!";

        // The Input and Output classes. These classes are not thread safe.
        Output output = new Output(new FileOutputStream("F:/springdemo/kryoFile"));
        kryo.writeObject(output, myKryoClass);
        output.close();

        Input input = new Input(new FileInputStream("F:/springdemo/kryoFile"));
        MyKryoClass readObject = kryo.readObject(input, MyKryoClass.class);
        System.out.println(readObject);
        input.close();

    }
    private static class MyKryoClass {
        String value;
    }
}
